﻿/*
 * Copyright (C) 2012, Jesus Requejo <jesus.requejo@gmail.com> 
 * Licensed under Microsoft Public License (Ms-PL)
 * http://www.microsoft.com/en-us/openness/licenses.aspx#MPL
*/

namespace Infrastructure {

   using System;
   using System.Diagnostics;
   using System.IO;
   
   public static class ProcessUtils {
      
      /// <summary>
      /// Runs supplied process with current user credentials. 
      /// </summary>
      /// <remarks>If the process to run requires elevated priviledges, it must supply its own manifest</remarks>
      /// <param name="name"></param>
      public static Process RunProcess(string name, string arguments = "") {
         
         string workingDir = Path.GetDirectoryName(name);

         if (String.IsNullOrEmpty(workingDir)) {
            workingDir = Environment.CurrentDirectory;
         }

         ProcessStartInfo processInfo = new ProcessStartInfo() {
            FileName = name,
            Arguments = arguments,
            WorkingDirectory = workingDir,
            UseShellExecute = true 
         };
         
         return Process.Start(processInfo);
      }
   }
}
